package com.fc.mall.portal.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.portal.dto.OssAccessInfoResult;
import com.fc.mall.portal.dto.OssCallbackResult;
import com.fc.mall.portal.dto.OssPolicyResult;
import com.fc.mall.portal.service.impl.OssServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Sunny on 2019/7/4.
 */

@Controller
@Api(tags = "OssController",description = "Oss管理")
@RequestMapping("/aliyun/oss")
public class OssController {
    @Autowired
    private OssServiceImpl ossService;

    @ApiOperation(value = "oss上传签名生成")
    @RequestMapping(value = "/policy",method = RequestMethod.GET)
    @ResponseBody
    public Result policy() {
        OssPolicyResult result = ossService.policy();
        return Result.success(result);
    }

    @ApiOperation(value = "oss上传成功回调")
    @RequestMapping(value = "callback",method = RequestMethod.POST)
    @ResponseBody
    public Object callback(HttpServletRequest request) {
        OssCallbackResult ossCallbackResult = ossService.callback(request);
        return Result.success(ossCallbackResult);
    }

    @ApiOperation(value = "获取oss授权的信息")
    @RequestMapping(value = "/accessinfo",method = RequestMethod.GET)
    @ResponseBody
    public Object accessInfo(){
        OssAccessInfoResult result = ossService.getAccessInfo();
        return Result.success(result);
    }
}
